安装 · Ceres Solver 中文教程 您所在的位置:网站首页 wget 安装cmake351 安装 · Ceres Solver 中文教程

安装 · Ceres Solver 中文教程

2024-05-24 01:21| 来源: 网络整理| 查看: 265

安装 获取源代码

你可以先从最新稳定发行版开始。

或者,如果你想获得最新版本,可以 clone 下面这个 git 目录:

git clone https://ceres-solver.googlesource.com/ceres-solver 依赖项

Ceres 依赖一些开源库,其中一部分是可选项。关于自定义编译选项的细节,参考自定义编译部分。

Eigen 3.2.2 或以上版本(强烈建议),3.1.0 或以上版本(最低要求)。

⚠️ 注意

Ceres 也使用 Eigen 作为稀疏线性代数运算库。参看 EIGENSPARSE 相关文档。

CMake 2.8.0 或以上版本。除 Android 外所有平台都要求。

glog 0.3.1 或以上版本。推荐。

glog 广泛应用于 Ceres 中,用于记录内存分配、求解过程各个部分的耗时、内部错误条件等详细信息。Ceres 的开发者频繁地用其监测和分析 Ceres 的运行表现。glog 允许你通过命令行来控制其行为。由 -logtostderr 指令开始,你可以加入 -v=N 来提高 N 的值,以获取关于 Ceres 内部的更多细节。

不幸的是,当前版本的 google-glog 无法用 Android NDK 编译。所以,Ceres 同时提供 glog 的一个小型替代品 miniglog,可以在编译选项中加入 MINIGLOG 来启动。

为了减少依赖项,在 Android 之外的平台使用 miniglog 似乎也很诱人。虽然没人阻止用户这么做,但我们强烈不建议,因为 miniglog 的性能、可控性、可用性都比 glog 差。

⚠️ 注意

如果你使用源代码来编译 glog,需要留意目前 glog 的单元测试部分(默认开启)无法直接基于 gflags 2.1 编译,这是因为 gflags 的命名空间从 google:: 改成了 gflags::。你可以从此处下载一个补丁来解决。

gflags,编译示例和测试案例所需。

SuiteSparse,求解大型稀疏线性系统所需。可选项;对于大型 bundle adjustment,强烈推荐。

CXSparese。和 SuiteSparse 相似,但更简单,速度较慢。CXSparse 不依赖 LAPACK 和 BLAS,可以简化编译流程,生成更小的二进制文件。可选项。

BLAS 和 LAPACK,为 SuiteSparse 所依赖。可选项,Ceres 中的部分操作所需。

对于 Mac OS X 之外的其他类 UNIX 系统使用者,我们推荐 ATLAS,它内置了 BLAS 和 LAPACK。使用 OpenBLAS 也是可行的,但注意要关掉 OpenBLAS 内部的多线程功能,因其与 Ceres 本身的多线程冲突。

Mac OS X 在 Accelerate 框架内提供了经过优化的 LAPACK 和 BLAS,能被 Ceres 的编译系统自动检测和使用。

Windows 上的情况复杂得多。LAPACK For Windows 有详细指导。

BLAS 和 LAPACK 为可选项,但为 SuiteSparse 所必需。

Linux

我们的演示使用 Ubuntu 这一发行版。

⚠️ 注意

至少在 Ubuntu 14.04 之前,官方软件包仓库中的 SuiteSparse 包(基于 SuiteSparse v3.4.0 构建)不能作为共享库用于 Ceres 的编译。因此,如果要使用 SuiteSparse 作为共享库来编译 Ceres,必须通过源安装或者外部 PPA 来安装 SuiteSparse(参看此处 bug report)。 建议使用最新版本的 SuiteSparse (在撰写本文时为 4.2.1)。

首先,安装所有依赖项:

# CMake sudo apt-get install cmake # google-glog + gflags sudo apt-get install libgoogle-glog-dev # BLAS & LAPACK sudo apt-get install libatlas-base-dev # Eigen3 sudo apt-get install libeigen3-dev # SuiteSparse and CXSparse (optional) # - If you want to build Ceres as a *static* library (the default) # you can use the SuiteSparse package in the main Ubuntu package # repository: sudo apt-get install libsuitesparse-dev # - However, if you want to build Ceres as a *shared* library, you must # add the following PPA: sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687 sudo apt-get update sudo apt-get install libsuitesparse-dev

现在可以编译、测试和安装 Ceres:

tar zxf ceres-solver-1.13.0.tar.gz mkdir ceres-bin cd ceres-bin cmake ../ceres-solver-1.13.0 make -j3 make test # Optionally install Ceres, it can also be exported using CMake which # allows Ceres to be used without requiring installation, see the documentation # for the EXPORT_BUILD_DIR option for more information. make install

你可以顺便跑一下内置示例中的 bundle adjustment 应用(来自华盛顿大学 BAL 数据集 [Agarwal]):

bin/simple_bundle_adjuster ../ceres-solver-1.13.0/data/problem-16-22106-pre.txt

该程序使用 DENSE_SCHUR 线性求解器,最高迭代次数为 10 次。预期输出如下:

ter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time 0 4.185660e+06 0.00e+00 1.09e+08 0.00e+00 0.00e+00 1.00e+04 0 7.59e-02 3.37e-01 1 1.062590e+05 4.08e+06 8.99e+06 5.36e+02 9.82e-01 3.00e+04 1 1.65e-01 5.03e-01 2 4.992817e+04 5.63e+04 8.32e+06 3.19e+02 6.52e-01 3.09e+04 1 1.45e-01 6.48e-01 3 1.899774e+04 3.09e+04 1.60e+06 1.24e+02 9.77e-01 9.26e+04 1 1.43e-01 7.92e-01 4 1.808729e+04 9.10e+02 3.97e+05 6.39e+01 9.51e-01 2.78e+05 1 1.45e-01 9.36e-01 5 1.803399e+04 5.33e+01 1.48e+04 1.23e+01 9.99e-01 8.33e+05 1 1.45e-01 1.08e+00 6 1.803390e+04 9.02e-02 6.35e+01 8.00e-01 1.00e+00 2.50e+06 1 1.50e-01 1.23e+00 Ceres Solver v1.13.0 Solve Report ---------------------------------- Original Reduced Parameter blocks 22122 22122 Parameters 66462 66462 Residual blocks 83718 83718 Residual 167436 167436 Minimizer TRUST_REGION Dense linear algebra library EIGEN Trust region strategy LEVENBERG_MARQUARDT Given Used Linear solver DENSE_SCHUR DENSE_SCHUR Threads 1 1 Linear solver threads 1 1 Linear solver ordering AUTOMATIC 22106, 16 Cost: Initial 4.185660e+06 Final 1.803390e+04 Change 4.167626e+06 Minimizer iterations 6 Successful steps 6 Unsuccessful steps 0 Time (in seconds): Preprocessor 0.261 Residual evaluation 0.082 Jacobian evaluation 0.412 Linear solver 0.442 Minimizer 1.051 Postprocessor 0.002 Total 1.357 Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 1.769766e-09


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有